<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Person(name, age) {
        this.name = name;
        this.age = age;
      }

      Person.prototype = {
        constructor: Person, // 确保 constructor 属性指向 Person
        love: function () {
          console.log("我喜欢吃饭");
        },
        haveqian: function () {
          console.log("没有钱");
        },
      };

      var p1 = new Person();
      //   p1.sayHello(); // 会抛出错误，因为 sayHello 方法已被丢弃
      p1.love(); // 输出: 我喜欢吃饭
      p1.haveqian(); // 输出: 没有钱
    </script>
  </body>
</html>
